﻿using ParkService.Core;
using System;
using System.Threading;
using Topshelf;
using Topshelf.Logging;

namespace ParkService
{
    class WindowService : ServiceControl
    {
        readonly string _serverWsUrl;
        readonly int _port;
        readonly int _hubId;
        WsClient _client = null;
        
        static readonly LogWriter _log = HostLogger.Get<WindowService>();

        public WindowService(string serverWsUrl, int port, int hubId)
        {
            _serverWsUrl = serverWsUrl;
            _port = port;
            _hubId = hubId;

            _client = new WsClient(serverWsUrl, _port, hubId);
        }

        public bool Start(HostControl hostControl)
        {
            _log.Info("WindowService Starting...");

            hostControl.RequestAdditionalTime(TimeSpan.FromSeconds(10));

            _client.Start();

            _log.Info("WindowService Started");

            return true;
        }

        public bool Stop(HostControl hostControl)
        {
            _log.Info("WindowService Stopped");
            _client.Stop();

            return true;
        }

        public bool Pause(HostControl hostControl)
        {
            _log.Info("WindowService Paused");

            return true;
        }

        public bool Continue(HostControl hostControl)
        {
            _log.Info("WindowService Continued");

            return true;
        }
    }
}